﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NewstorePlateformeDAO;

namespace NewstorePlateformeApp.Controllers
{ 
    public class ADM_ArticlesCmdController : Controller
    {
        private Newstore_PL_GOLD_BDDEntities db = new Newstore_PL_GOLD_BDDEntities();

        //
        // GET: /ADM_ArticlesCmd/

        public ViewResult Index()
        {
            var c_gold_commande_marchandise_catalogue = db.C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE.Include("GOLD_COMMANDE").Include("MARCHANDISE_CATALOGUE");
            return View(c_gold_commande_marchandise_catalogue.ToList());
        }

        //
        // GET: /ADM_ArticlesCmd/Details/5

        public ViewResult Details(int id)
        {
            C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE c_gold_commande_marchandise_catalogue = db.C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE.Single(c => c.id_gOLD_COMMANDE_mARCHANDISE_CATALOGUE == id);
            return View(c_gold_commande_marchandise_catalogue);
        }

        //
        // GET: /ADM_ArticlesCmd/Create

        public ActionResult Create()
        {
            ViewBag.idGOLD_COMMANDE = new SelectList(db.GOLD_COMMANDE, "idGOLD_COMMANDE", "num_commande");
            ViewBag.idMARCHANDISE_CATALOGUE = new SelectList(db.MARCHANDISE_CATALOGUE, "idMarchandise_Catalogue", "libelle");
            return View();
        } 

        //
        // POST: /ADM_ArticlesCmd/Create

        [HttpPost]
        public ActionResult Create(C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE c_gold_commande_marchandise_catalogue)
        {
            if (ModelState.IsValid)
            {
                db.C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE.AddObject(c_gold_commande_marchandise_catalogue);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.idGOLD_COMMANDE = new SelectList(db.GOLD_COMMANDE, "idGOLD_COMMANDE", "num_commande", c_gold_commande_marchandise_catalogue.idGOLD_COMMANDE);
            ViewBag.idMARCHANDISE_CATALOGUE = new SelectList(db.MARCHANDISE_CATALOGUE, "idMarchandise_Catalogue", "libelle", c_gold_commande_marchandise_catalogue.idMARCHANDISE_CATALOGUE);
            return View(c_gold_commande_marchandise_catalogue);
        }
        
        //
        // GET: /ADM_ArticlesCmd/Edit/5
 
        public ActionResult Edit(int id)
        {
            C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE c_gold_commande_marchandise_catalogue = db.C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE.Single(c => c.id_gOLD_COMMANDE_mARCHANDISE_CATALOGUE == id);
            ViewBag.idGOLD_COMMANDE = new SelectList(db.GOLD_COMMANDE, "idGOLD_COMMANDE", "num_commande", c_gold_commande_marchandise_catalogue.idGOLD_COMMANDE);
            ViewBag.idMARCHANDISE_CATALOGUE = new SelectList(db.MARCHANDISE_CATALOGUE, "idMarchandise_Catalogue", "libelle", c_gold_commande_marchandise_catalogue.idMARCHANDISE_CATALOGUE);
            return View(c_gold_commande_marchandise_catalogue);
        }

        //
        // POST: /ADM_ArticlesCmd/Edit/5

        [HttpPost]
        public ActionResult Edit(C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE c_gold_commande_marchandise_catalogue)
        {
            if (ModelState.IsValid)
            {
                db.C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE.Attach(c_gold_commande_marchandise_catalogue);
                db.ObjectStateManager.ChangeObjectState(c_gold_commande_marchandise_catalogue, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.idGOLD_COMMANDE = new SelectList(db.GOLD_COMMANDE, "idGOLD_COMMANDE", "num_commande", c_gold_commande_marchandise_catalogue.idGOLD_COMMANDE);
            ViewBag.idMARCHANDISE_CATALOGUE = new SelectList(db.MARCHANDISE_CATALOGUE, "idMarchandise_Catalogue", "libelle", c_gold_commande_marchandise_catalogue.idMARCHANDISE_CATALOGUE);
            return View(c_gold_commande_marchandise_catalogue);
        }

        //
        // GET: /ADM_ArticlesCmd/Delete/5
 
        public ActionResult Delete(int id)
        {
            C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE c_gold_commande_marchandise_catalogue = db.C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE.Single(c => c.id_gOLD_COMMANDE_mARCHANDISE_CATALOGUE == id);
            return View(c_gold_commande_marchandise_catalogue);
        }

        //
        // POST: /ADM_ArticlesCmd/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE c_gold_commande_marchandise_catalogue = db.C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE.Single(c => c.id_gOLD_COMMANDE_mARCHANDISE_CATALOGUE == id);
            db.C_gOLD_COMMANDE_mARCHANDISE_CATALOGUE.DeleteObject(c_gold_commande_marchandise_catalogue);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}